<link href="css/style.css" rel="stylesheet" type="text/css" />
<?php 
		
		$daction = $_SESSION['action'];
		
		
		mysql_query("UPDATE listapprove SET isView='1' WHERE (IDGroupApprove=(SELECT a.IDGroupApprove FROM approvedoc a WHERE a.IDApproveDoc='$id'));");
		
		$query = mysql_query("select a.Tile,a.Content,e.Fullname,a.Timecreate,a.IDGroupApprove,a.IDStatus from approvedoc a 
				inner join employee e on a.IDEmployee = e.IDEmployee where a.IDApproveDoc = '$id'");
		while ($row = mysql_fetch_array($query))
		{
			$dtitle = $row['Tile'];
			$dcontent = $row['Content'];
			$dtime = $row['Timecreate'];
			$duser = $row['Fullname'];
			$didgroupapprover = $row['IDGroupApprove'];
			$dstatus = $row['IDStatus'];
		}
		
		$flagmysending=false;
		if($daction == "my_sending"){
			$result=mysql_query("select listapprove.ID FROM listapprove WHERE IDGroupApprove='".$didgroupapprover."' and (IDStatus = 1 or IDStatus = 3 or IDStatus > 9)");
			if(mysql_num_rows($result)==0){
				$flagmysending=true;
			}
		}
		
		if($daction=="re_not_approve"){
		$lang = $_SESSION['lang'];
		$queryDepartment = mysql_query("SELECT d.IDDepartment,dl.DepartmentName FROM department d,department_lang dl WHERE d.IDDepartment=dl.IDDepartment AND dl.LangID='$lang';");
		$queryReference = mysql_query("SELECT e.IDEmployee,e.FullName FROM list_reference lr,employee e WHERE e.IDEmployee=lr.id_employee AND lr.id_group='$didgroupapprover' AND lr.id_manager='$id_employee' AND lr.id_status !=1;");

			include 'popup/popup_reference.php';
		}
		
		if(isset($_SERVER['HTTP_REFERER'])){
			$url=split('\&page=',$_SERVER['HTTP_REFERER']);
			$_SESSION['backpage']=$url[0];
		}
	?>
<style>.print{font-size:18px !important;margin:auto !important;width:90% !important;}
			.print table {border-collapse:collapse !important;width:90% !important;}
			.print td{border: 1px solid #999 !important;padding: 5px !important}
			
			.print td .first{
				background: #E8E8E8 !important; 
				padding:5px !important; 	
				font-weight:bold !important;; 
			}
			
</style>
<script>
			
			function printStart(){
				document.getElementById("header").style.display = "none";
				document.getElementById("menuleft").style.display = "none";
				document.getElementById("menu").style.display = "none";
				document.getElementById("footer").style.display = "none";
				document.getElementById("list").className="print";
				window.print();
				if(/Chrome/.test(navigator.userAgent)){
					  $(window).focus(function(){
						  location.reload(true);
					  });
					} else {
						  location.reload(true);
				}
			}
		
		</script>
<div class="title"></div>
<form action="approve-handle.php" method="post">
<input type="hidden" name="id" value="<?=$id?>" />
<input type="hidden" name="type" value="<?=$type?>" />
<input type="hidden" name="action" value="<?=$daction?>" />
<div class="main_content" style="min-height: 895px;background-color: white">
<div id="menu">
            <ul class="top_but">
	<?php if($daction=="re_not_approve"  || $daction=="my_saved"){?>
				<li><?php if(isset($_REQUEST['page'])){?>
						<input type="hidden" name="page" value="<?=$_REQUEST['page']?>" />
						<a href="<?=$_SESSION['backpage']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /></a>
					<?php }else{?>
						<a href="<?=$_SESSION['backpage']?>"><img src="images/back.png" alt="" /></a>
					<?php }?><p class="hidden"><?=$l_back?></p></li>
	<?php }else{?>
				<li><?php if(isset($_REQUEST['page'])){?>
						<input type="hidden" name="page" value="<?=$_REQUEST['page']?>" />
						<a href="<?=$_SESSION['backpage']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /></a>
					<?php }else{?>
						<a href="<?=$_SESSION['backpage']?>"><img src="images/back.png" alt="" /></a>
					<?php }?><p class="hidden"><?=$l_back?></p></li>
				<li><a href="printer/printer7.php?id=<?=$id?>&type=<?=$type?>" target="_blank"><img src="images/print.png" alt="" /></a><p class="hidden"><?=$l_print?></p></li>
	<?php }?>
	<?php if($daction=="mybin_senddoc"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Restore" value="" style="background:url(images/restore.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_restore?></p></li>
	<?php }?>
	<?php if($daction=="my_approved"){
			//$_SESSION['idGroup']=$didgroupapprover;
			//$_SESSION['id_employee']=$id_employee;
	?>
				<li><a href="newform-<?=$id?>&<?=$type?>&<?=$page?>&forward"><img src="images/forward.png" alt="" /></a><p class="hidden"><?=$l_forward?></p></li>
	<?php }?>
	<?php if($daction=="re_not_approve"){
		$_SESSION['idGroup']=$didgroupapprover;
		$_SESSION['id_employee']=$id_employee;
	?>
				
				
				<li><input type="submit" name="Approve" value="" style="background:url(images/ok.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_approve?></p></li>
				<li><input type="submit" name="Reject" value="" style="background:url(images/deny.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_reject?></p></li>
				<li><input type="button" onclick="popup_window_show('#sample', { pos : 'window-center', width : '600px', height:'800px'});" value="" name="Reference" style="background:url(images/refer.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto" /><p class="hidden"><?=$l_reference?></p></li>
	<?php }?>
	<?php
		 if($daction == "re_reference_waiting"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Accept" value="" style="background:url(images/ok.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_accept?></p></li>
	<?php }?>
	
	<?php
	if($daction == "my_declined" || $flagmysending==true){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Edit" value="" style="background:url(images/edit.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?php echo $l_edit?></p></li>
				<li><input type="submit" name="Delete" value="" style="background:url(images/trash.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?php echo $l_delete?></p></li>
	<?php }?>
	
			</ul>
			</div>
			<div id="list">
            <table class="tcontent"   style="text-align:center;" cellpadding="5" cellspacing="0">
            	<tr>
                	<td class="col_left" ><?=$l_title?></td>
                    <td colspan="3"><div align="left"><?=$dtitle?></div></td>
           	  	</tr>
                <tr>
                	<td class="col_left" width="15%"><?=$l_created_date?></td>
                  	<td><div align="left"><?=$dtime?></div></td>
                    <td class="col_left" width="15%"><?=$l_writer?></td>
                    <td><div align="left"><?=$duser?></div></td>       
                </tr>                 
                <tr>
                	<td class="col_left" width="15%"><?=$l_approver?></td>
                  	<td colspan="3" style="padding: 1px 1px">
                    	<table class="tcontent" style="text-align:center;" cellpadding="5" cellspacing="0" >
                        	
                    				<?
                    				//Get group approver
                    				$query1 = mysql_query("SELECT l.IDStatus,l.DateApprove,e.Fullname,l.Description,l.IDEmployee FROM listapprove l
                    						INNER JOIN employee e ON l.IDEmployee = e.IDEmployee
                    						WHERE CONVERT(l.IDGroupApprove USING utf8) = CONVERT('$didgroupapprover' USING utf8)
                    						ORDER BY l.Order ASC");
                    				
                    				$i=1;
                    				while ($row = mysql_fetch_array($query1))
                    				{
                    					$dnameapprover = $row['Fullname'];
                    					$ddateapproved = $row['DateApprove'];
                    					$dcommentm=$row['Description'];
                    					$didEmployee=$row['IDEmployee'];
                    					if ($row['IDStatus'] == 1){
	                    					$dstatus=$l_status_complete;
	                    				} else if ($row['IDStatus'] == 2){
	                    					$dstatus=$l_status_pending;
	                    				}else if ($row['IDStatus'] == 3){
	                    					$dstatus=$l_status_declined;
	                    				}else if ($row['IDStatus'] == 4){
	                    					$dstatus=$l_status_saved;
	                    				}else if ($row['IDStatus'] == 5){
	                    					$l_status_reference;
	                    				}
                    				?>
                    				
                    				<tr>	
                    					<td rowspan="2"  style="padding: 5px 5px;color:blue;width: 100px"><?=$l_step?> <?=$i?> </td>
                    					<td  style="padding: 5px 5px;width: 450px">
		                    				<span style="display: block;">
		                    					<b><?=$dnameapprover?></b>_<?=$dstatus?> <?=$ddateapproved?>
		                    				</span>
	                    				</td>
	                    				<td style="padding: 5px 5px"> <div align="left"><?=$l_reference?> :
		                                	<?
		                    				//Get list references
		                    				$query2 = mysql_query("SELECT e.Fullname FROM list_reference l
		                    						INNER JOIN employee e ON l.id_employee = e.IDEmployee
		                    						WHERE CONVERT(l.id_group USING utf8) = CONVERT('$didgroupapprover' USING utf8) AND
		                    									l.id_manager='$didEmployee'") ;
		                    				
		                    				while ($row1 = mysql_fetch_array($query2))
		                    				{
		                    					$dnamereferences = $row1[Fullname];
		                    				?>
		                    				<b><?=$dnamereferences?></b>;
		                    				<?
		                    				}
		                    				?>
		                                
		                               </div> </td>
                    				</tr>
                    				<?php if($ddateapproved ==null){?>
                    				<tr >
                    				</tr>
                    				<?php }else{?>	
                    				<tr >
                    					<td colspan="2" style="padding: 5px 5px"><div align="left"><b><?=$l_comment?> : </b><?=$dcommentm?> </div></td>
                    				</tr>
                    				<?php }?>
                    				
                    				
                    				<?
                    					$i++;
                    				}
                    				?>
                    				
                        </table>                    </td>
                </tr>  
                <?php 
               	if($daction == "re_not_approve"){
               		
               ?> 
                <tr>
                	<td class="col_left" width="15%"><?=$l_comment?></td>
                  	<td colspan="3" style="padding: 1px 1px"><textarea name="textarea" rows="3" cols="5" style="width:99%; border:1px solid #c4c0c9"></textarea></td>
                </tr>    
                <?php } ?>
                <tr>
                	<td class="col_left" width="15%" style="vertical-align: top"><?=$l_content?></td>
                  	<td colspan="3" style="padding: 0px 0px"></td>
                </tr>
                
                <tr>
                  	<td colspan="4"  class="tcontent1"><?=$dcontent?></td>
                </tr>
                                       
            </table>
            </div>
      </div>
</form>